<?php
/**
 * Created by PhpStorm.
 * User: 低调
 * Date: 2018/5/21
 * Time: 21:55
 */
include("head.php");
session_start();
$id = $_SESSION['id'];
$author = $_SESSION['username'];
if(isset($_POST['submit'])){
    $type = $_POST['type'];
    $title = $_POST['title'];
    $content = $_POST['content'];
    if($_POST['status']=='2')
        $status = 2;
    else
        $status = 1;
    $sql = "INSERT INTO Article(`id`,`uid`,`author`,`type`,`title`,`time`,`content`,`status`) VALUES ('','$id','$author','$type','$title',now(),'$content','$status')";
    if(mysqli_query($conn,$sql))
        echo "<script>alert('文章发表成功');location.href='articleList.php'</script>";
    else
        echo "<script>alert('文章发表失败');history.go(-1);</script>";
}
?>

<!-- 内容区域 -->
<div class="tpl-content-wrapper">

    <div class="row-content am-cf">

        <div class="row">

            <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
                <div class="widget am-cf">
                    <div class="widget-head am-cf">
                        <div class="widget-title am-fl">发表新文章</div>
                    </div>
                    <div class="widget-body am-fr">

                        <form class="am-form tpl-form-border-form" method="post" action="">
                            <div class="am-form-group">
                                <label for="user-name" class="am-u-sm-12 am-form-label am-text-left">标题 <span class="tpl-form-line-small-title">Title</span></label>
                                <div class="am-u-sm-12">
                                    <input type="text" class="tpl-form-input am-margin-top-xs" id="user-name" placeholder="请输入标题文字" name="title">
                                    <small>请填写标题文字10-20字左右。</small>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label for="user-phone" class="am-u-sm-12 am-form-label am-text-left">作者 <span class="tpl-form-line-small-title">Author</span></label>
                                <div class="am-u-sm-12  am-margin-top-xs">
                                        <input type="text" class="tpl-form-input am-margin-top-xs" id="user-name" placeholder="请输入作者" name="author" value="<?php echo $author;?>">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label for="user-weibo" class="am-u-sm-12 am-form-label  am-text-left">文章分类 <span class="tpl-form-line-small-title">Type</span></label>
                                <div class="am-u-sm-12">
                                    <input type="text" id="user-weibo" class="am-margin-top-xs" placeholder="标注文章类型" name="type">
                                </div>
                            </div>

                            <div class="am-form-group">
                                <label for="user-intro" class="am-u-sm-12 am-form-label  am-text-left">隐藏文章</label>
                                <div class="am-u-sm-12">
                                    <div class="tpl-switch">
                                        <input type="checkbox" class="ios-switch bigswitch tpl-switch-btn am-margin-top-xs" checked="" name="status" value=2>
                                        <div class="tpl-switch-btn-view">
                                            <div>
                                                <input type="checkbox" class="ios-switch bigswitch tpl-switch-btn am-margin-top-xs" name="status" value=1>
                                            </div>
                                        </div>
                                    </div>

                                </div>
                            </div>

                            <div class="am-form-group">
                                <label for="user-intro" class="am-u-sm-12 am-form-label  am-text-left">文章内容</label>
                                <div class="am-u-sm-12 am-margin-top-xs">
                                    <textarea class="" rows="10" id="user-intro" placeholder="请输入文章内容" name="content"></textarea>
                                </div>
                            </div>

                            <div class="am-form-group">
                                <div class="am-u-sm-12 am-u-sm-push-12">
                                    <button type="submit" name="submit" class="am-btn am-btn-primary tpl-btn-bg-color-success ">提交</button>
                                </div>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>